<script>
	import amap  from './common/lib/amap-wx.js';  
	const AMAPWX_KEY = '5fc46a5bd97733eac183c849cf0fccd6';
	var amapPlugin = null;
	export default {
		onLaunch: function() {
			this.$store.commit('initUser');
			amapPlugin = new amap.AMapWX({  
				key:AMAPWX_KEY
			}); 
			/**
			 * 位置信息
			 * */
			amapPlugin.getRegeo({  
				success: (data) => {
					let city = data[0].regeocodeData.addressComponent.city;
					this.$store.commit('updateCity',city);
				}  
			});  
			/**
			 * 实况天气
			 * */
			amapPlugin.getWeather({
				success: (data) => {
					let d = new Date().getDay();
					switch(d) {
						case 1:
						   d = '星期一';
						   break;
						case 2:
						   d = '星期二';
						   break;
						case 3:
						   d = '星期三';
						   break;
						case 4:
						   d = '星期四';
						   break;
						case 5:
						   d = '星期五';
						   break;
						case 6:
						   d = '星期六';
						   break;
						case 0:
						   d = '星期日';
						   break;
					};
					let r = data.liveData.reporttime.split(' ')[0];
					let t = data.liveData.weather;
					let c = data.liveData.temperature;
					let f = data.liveData.winddirection + '风';
					let w = `${r} ${d} ${t} ${c}℃ ${f}`;
					this.$store.commit('updateWeather',w);
				}  
			});
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style lang="scss">
    @import "uview-ui/index.scss";
    @import url("./common/uni.css");
    @import url("./common/zcm-main.css");
    @import url("./common/common.css");
    @import url("./common/icon.css");
    @import url("./common/animate.css");
</style>
